package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CBasicsWorkDao;
import com.hongxun.modules.csg.entity.CBasicsWorkEntity;
import com.hongxun.modules.csg.service.CBasicsWorkService;



@Service("cBasicsWorkService")
public class CBasicsWorkServiceImpl implements CBasicsWorkService {
	@Autowired
	private CBasicsWorkDao cBasicsWorkDao;
	
	@Override
	public CBasicsWorkEntity queryObject(String guid){
		return cBasicsWorkDao.queryObject(guid);
	}
	
	@Override
	public List<CBasicsWorkEntity> queryList(Map<String, Object> map){
		return cBasicsWorkDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cBasicsWorkDao.queryTotal(map);
	}
	
	@Override
	public void save(CBasicsWorkEntity cBasicsWork){
		if(cBasicsWork.getGuid()==null||cBasicsWork.getGuid().equals("")) {
			cBasicsWork.setGuid(UUID.randomUUID().toString());
		}

		cBasicsWorkDao.save(cBasicsWork);
	}
	
	@Override
	public void update(CBasicsWorkEntity cBasicsWork){
		cBasicsWorkDao.update(cBasicsWork);
	}
	
	@Override
	public void delete(String guid){
		cBasicsWorkDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cBasicsWorkDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CBasicsWorkEntity> entities) {
		for (CBasicsWorkEntity d : entities) {
			if (d.getBWDatastate().equals("删除")) {
				cBasicsWorkDao.delete(d.getGuid());
			} else {
				CBasicsWorkEntity cBasicsWorkEntity = cBasicsWorkDao.queryObject(d.getGuid());
				if (cBasicsWorkEntity == null) {
					cBasicsWorkDao.save(d);
				} else {
					cBasicsWorkDao.update(d);
				}
			}
		}
	}
	
}
